<!DOCTYPE html>
<title>Transaction from removed execution context</title>
<script>
if (window.testRunner) {
  testRunner.dumpAsText();
  testRunner.waitUntilDone();
}

var script = `
var db = openDatabase('db' + Math.random() + Date.now(), '1.0', 'test database', 2*1024);
db.transaction(tx => {
    tx.executeSql('DROP TABLE IF EXISTS TestTable');
    tx.executeSql('CREATE TABLE IF NOT EXISTS TestTable (id unique,text)');
    tx.executeSql('DELETE FROM TestTable WHERE id=?', [1]);
    frameElement.remove();
});
`;

window.addEventListener('DOMContentLoaded', e => {
  var srcdoc = '<script>' + script + '<\/script>';
  var iframe = document.createElement('iframe');
  document.body.appendChild(iframe);
  iframe.srcdoc = srcdoc;
  waitUntil(
    () => iframe.parentNode === null,
    () => window.testRunner && testRunner.notifyDone()
  );
});

// Poll (10ms) until testFunc returns true, then execute callback().
function waitUntil(testFunc, callback) {
  setTimeout(() => {
    if (testFunc())
      callback();
    else
      waitUntil(testFunc, callback);
  }, 10);
}
</script>
<body>
If it doesn't crash, this test has passed.
</body>
